package com.zprmb.udzt.view;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.zprmb.udzt.R;
import com.zprmb.udzt.util.BitmapUtils;
import com.zprmb.udzt.util.GetWindowWidth;

public class FirstDialog extends Dialog implements View.OnClickListener {

	private Activity mActivity;
	private ImageView iv_dialog;
	private Bitmap bitmap;
	private RelativeLayout rl_iamgedialog;
	private int home=0,assets;
	private View view_pass;
	private Scrollbottom scrollbottom;

	public FirstDialog(Activity context, int type) {
		super(context, R.style.first_dialog);
		setImmersionStatus();
		setContentView(R.layout.image_dialog);// loading
		mActivity = context;
		
		setProperty();
		view_pass=(View)findViewById(R.id.view_pass);
		iv_dialog = (ImageView) findViewById(R.id.iv_dialog);
		rl_iamgedialog = (RelativeLayout) findViewById(R.id.rl_iamgedialog);
		RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(GetWindowWidth.getWidth(mActivity),GetWindowWidth.getHeight(mActivity));
		iv_dialog.setLayoutParams(rl);
		view_pass.setOnClickListener(this);
		iv_dialog.setOnClickListener(this);
		setCancelable(false);
		switch (type) {
			case 1:
//				bitmap=BitmapUtils.readBitMap(mActivity, R.drawable.bbt_index1);
				bitmap = BitmapUtils.readBitMap(mActivity,R.drawable.bbt_index1);
				break;
			case 2:
				bitmap = BitmapUtils.readBitMap(mActivity,R.drawable.bbt_bccb);
				break;
			case 3:
				bitmap = BitmapUtils.readBitMap(mActivity ,R.drawable.bbt_assets_1);
				break;
			case 4:
				bitmap = BitmapUtils.readBitMap(mActivity ,R.drawable.bbt_abc);
				break;
		}
		iv_dialog.setImageBitmap(bitmap);
	}
	public void setscrollbottom(Scrollbottom scrollbottom){
	this.scrollbottom=scrollbottom;
	}
	public interface Scrollbottom{
		void tobottom();
	}
	private void setImmersionStatus() {
		if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
			// 透明状态栏
			getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			// 透明导航栏
			//getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
		}
	}
	private void setProperty() {
		Window window = getWindow();
		WindowManager.LayoutParams p = window.getAttributes();
		Display d = getWindow().getWindowManager().getDefaultDisplay();
		p.height = (int) (d.getHeight() * 1);
		p.width = (int) (d.getWidth() * 1);
		getWindow().setAttributes(p);
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.iv_dialog:
			
			if(assets==0){
				bitmap = BitmapUtils.readBitMap(mActivity ,R.drawable.bbt_assets_2);
				iv_dialog.setImageBitmap(bitmap);
				assets=assets+1;
			}
//			else if(assets==1){
//				scrollbottom.tobottom();
//				bitmap = BitmapUtils.readBitMap(mActivity ,R.drawable.bbt_assets_3);
//				iv_dialog.setImageBitmap(bitmap);
//				assets=assets+1;
//			}
			else{
				
				dismiss();
				bitmap.recycle();
				System.gc();
			}
			break;
		case R.id.view_pass:
			dismiss();
			break;
		}
	}
}
